package com.zhongshengnetwork.rightbe.wzt.activity;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.provider.ContactsContract;
//import android.support.design.widget.AppBarLayout;
//import android.support.design.widget.CollapsingToolbarLayout;
//import android.support.design.widget.TabLayout;
//import android.support.v4.view.ViewPager;
//import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
//import android.support.v7.widget.ButtonBarLayout;
//import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.tabs.TabLayout;
import com.gyf.barlibrary.ImmersionBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
//import com.scwang.smartrefresh.layout.util.DensityUtil;
import com.wang.avi.AVLoadingIndicatorView;
import com.zhongshengnetwork.rightbe.Constant.APIKey;
import com.zhongshengnetwork.rightbe.Constant.Constant;
import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.MainActivity;
import com.zhongshengnetwork.rightbe.OnePiexlActivity;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.BroadcastDefine;
import com.zhongshengnetwork.rightbe.common.CircleTransform;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.GsonTools;
import com.zhongshengnetwork.rightbe.common.HandlerDefine;
import com.zhongshengnetwork.rightbe.common.ScreenUtils;
import com.zhongshengnetwork.rightbe.common.activity.ReportActivity;
import com.zhongshengnetwork.rightbe.common.customview.ActionSheetDialog;
import com.zhongshengnetwork.rightbe.common.customview.CustomDialog;
import com.zhongshengnetwork.rightbe.common.customview.KeyMapDailog;
import com.zhongshengnetwork.rightbe.common.utils.ToastUtil;
import com.zhongshengnetwork.rightbe.dbservice.LangPublishService;
import com.zhongshengnetwork.rightbe.gsonmodel.CommonModel;
import com.zhongshengnetwork.rightbe.gsonmodel.DryCommentModel;
import com.zhongshengnetwork.rightbe.gsonmodel.WeiShuInfoDetailModel;
import com.zhongshengnetwork.rightbe.https.HttpCallBack;
import com.zhongshengnetwork.rightbe.https.HttpsUtils;
import com.zhongshengnetwork.rightbe.lang.activity.LangPublishActivity;
import com.zhongshengnetwork.rightbe.lang.activity.SelfImagePreviewActivity;
import com.zhongshengnetwork.rightbe.lang.activity.UserLangActivity;
import com.zhongshengnetwork.rightbe.login.BDThirdActivity;
import com.zhongshengnetwork.rightbe.login.LoginActivity;
import com.zhongshengnetwork.rightbe.wzt.view.AdapterPage;
import com.zhongshengnetwork.rightbe.wzt.view.WZTCommentFragment;
import com.zhongshengnetwork.rightbe.wzt.view.WZTContentFragment;
import com.zhongshengnetwork.rightbe.wzt.view.WZTLikeFragment;
import com.zhongshengnetwork.rightbe.wzt.view.WZTSubscribeFragment;

import java.io.File;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

import static com.huantansheng.easyphotos.constant.Code.REQUEST_PERMISSION;

public class WZTActivity extends WZTBaseActivity implements WZTContentFragment.MyListener, WZTCommentFragment.MyCommentListener {

    public static final String PACKEGE_GAODE="com.autonavi.minimap";
    public static final String PACKEGE_BAIDU="com.baidu.BaiduMap";
    public static final String PN_TENCENT_MAP = "com.tencent.map"; // 腾讯地图包名
    private List<String> mapList;

    private static final int REQUEST_PUBLISH = 1002;
    private static final int REQUEST_EDIT = 1003;
    public static final int REQUEST_CONTENT_EDIT = 1004;
    public static final int REQUEST_CONTENT_ORDER = 1005;
    private WeiShuInfoDetailModel weiShuInfoDetailModel;

    private ViewPager viewpager;
    private ImageView iv_parallax,iv_back,iv_date;
    //private SmartRefreshLayout refreshLayout;

    private RelativeLayout title_layout,rl_allinfo;
    private CollapsingToolbarLayout collapsing_toolbar;
    private AppBarLayout appbar;
    private Toolbar toolbar;
    private int mOffset = 0;
    boolean isblack = false;//状态栏字体是否是黑色
    boolean iswhite = true;//状态栏字体是否是亮色
    private TabLayout tabLayout;
    private int selectIndex = 0;
    private int topHeight = 0;

    private WZTContentFragment wztContentFragment;
    private WZTCommentFragment wztCommentFragment;

    //头部布局
    private ImageView wzt_icon;
    private TextView wzt_title;
    private ImageView wzt_user_header;
    private ImageView wzt_user_private;
    private TextView wzt_user_nickanme;
    private TextView wzt_detail;
    private RelativeLayout wzt_detail_parent;

    private RelativeLayout wzt_subscribe_layout;
    private ImageView wzt_subscribe_icon;
    private TextView wzt_subscribe_text;
    private TextView wzt_subscribe_count;

    private RelativeLayout wzt_like_layout;
    private ImageView wzt_like_icon;
    private TextView wzt_like_text;
    private TextView wzt_like_count;

    private RelativeLayout wzt_comment_layout;
    private ImageView wzt_comment_icon;
    private TextView wzt_comment_text;
    private TextView wzt_comment_count;

    private RelativeLayout wzt_share_layout;
    private ImageView wzt_share_icon;
    private TextView wzt_share_text;
    private TextView wzt_share_count;

    private RelativeLayout wzt_location_layout;
    private ImageView wzt_location_icon;
    private TextView wzt_location_text;
    private TextView wzt_location_count;
    private LinearLayout wzt_detail_location;

    private RelativeLayout wzt_user_layout;

    //评论弹出框
    private KeyMapDailog dialog = null;

    //微纸条详情页面
    private RelativeLayout wzt_detail_layout;
    private ImageView wzt_detail_bg;
    private ImageView wzt_detail_icon;
    private TextView wzt_detail_title;

    private TextView wzt_detail_label_1;
    private TextView wzt_detail_label_2;
    private TextView wzt_detail_label_3;

    private TextView wzt_detail_location_text;

    private TextView wzt_detail_layout_text;

    private RelativeLayout load_avi;
    private AVLoadingIndicatorView avi;

    private RelativeLayout iv_back_layout;
    private RelativeLayout iv_date_layout;

    private boolean mReceiverTag = false;   //广播接受者标识
    public MyHandler myHandler;
    private LinearLayout publishing_layout;
    private ImageView publishing_icon;
    private TextView publishing_text;
    private Animation operatingAnim;


    boolean isDeleteClassify = false;
    private LinearLayout wzt_detail_classify;
    private TextView wzt_detail_classify_text;

    private boolean isFirstOpen = true;

    /**
     * 注册广播
     * @author Gordon
     */
    public void registerBoradcastReceiver(){
        if (!mReceiverTag) {     //在注册广播接受者的时候 判断是否已被注册,避免重复多次注册广播
            IntentFilter myIntentFilter = new IntentFilter();
            mReceiverTag = true;    //标识值 赋值为 true 表示广播已被注册
            //添加接收广播类型
            myIntentFilter.addAction(BroadcastDefine.WZTContentPublished_Notify_Action);
            myIntentFilter.addAction(BroadcastDefine.WZTContentPublishing_Notify_Action);
            //注册广播
            registerReceiver(mBroadcastReceiver, myIntentFilter);
            myHandler = new MyHandler(WZTActivity.this);
        }
    }

    /**
     * 广播接收者
     * @author Gordon
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {

            String action = intent.getAction();
            Log.e("TAG","onReceive接收到广播了=" +action + "\n");
            if (action.equals(BroadcastDefine.WZTContentPublished_Notify_Action)){
                Message msg = new Message();
                msg.obj = new String(HandlerDefine.wztpublishnotifymsg);
                myHandler.sendMessage(msg);
            }else if (action.equals(BroadcastDefine.WZTContentPublishing_Notify_Action)){
                Message msg = new Message();
                msg.obj = new String(HandlerDefine.wztpublishingnotifymsg);
                myHandler.sendMessage(msg);
            }
        }
    };

    static class MyHandler extends Handler {

        WeakReference<WZTActivity> mWeakReference;
        public MyHandler(WZTActivity activity)
        {
            mWeakReference=new WeakReference<WZTActivity>(activity);
        }

        //子类重写次方法，处理消息

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if(mWeakReference == null){
                return;
            }
            final WZTActivity activity = mWeakReference.get();
            if (activity == null){
                return;
            }

            try {
                if (msg == null || msg.obj == null || msg.obj.toString() == null){
                    return;
                }
                if (msg.obj.toString().equals(HandlerDefine.wztpublishnotifymsg)){
                    activity.updatePublish(false);
                    if (activity.wztContentFragment != null){
                        activity.wztContentFragment.getData(true);
                    }
                }else if(msg.obj.toString().equals(HandlerDefine.wztpublishingnotifymsg)){
                    activity.updatePublish(false);
                }
            }catch (Exception e){
                LangPublishActivity.uploadError("MainActivity报错："+CommonUtils.formatString(e.getMessage()));
            }
        }
    }

    public void updatePublish(boolean isFinish){
        if (isFinish == true){
            if (publishing_layout.getVisibility() == View.VISIBLE){
                publishing_icon.clearAnimation();
                publishing_layout.setVisibility(View.GONE);
            }
            return;
        }
        if (CommonUtils.isLogin() == true){
            long count = LangPublishService.getWZTPublishCount(CustomApplication.loginModel.getUid());
            if (count > 0){
                if (publishing_layout.getVisibility() == View.GONE){
                    publishing_layout.setVisibility(View.VISIBLE);
                    if (operatingAnim != null) {
                        publishing_icon.startAnimation(operatingAnim);
                    }
                }
                publishing_text.setText(count+"个内容发布中...");

            }else {
                if (publishing_layout.getVisibility() == View.VISIBLE){
                    publishing_icon.clearAnimation();
                    publishing_layout.setVisibility(View.GONE);
                }
            }
            Log.e("TAG","发布数量："+count);
        }
    }

    @Override
    public void publishSend() {

        if (bindMobile() == true){
            return;
        }

        Intent intent = new Intent(WZTActivity.this, WZTContentPublishActivity.class);
        intent.putExtra("id",weiShuInfoDetailModel.getId());
        intent.putExtra("contentType",weiShuInfoDetailModel.getContentType());
        startActivityForResult(intent, REQUEST_PUBLISH);
    }

    //绑定手机号
    private boolean bindMobile(){
        if (CommonUtils.isLogin() == true){
            if (!CommonUtils.isEmpty(CustomApplication.loginModel.getNeed()) && CustomApplication.loginModel.getNeed().equals("1")){
                if (CommonUtils.isEmpty(CustomApplication.loginModel.getMobile())){
                    Intent intent = new Intent(WZTActivity.this, BDThirdActivity.class);
                    startActivity(intent);
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public void goContentDetail() {
        //rl_allinfo.setVisibility(View.INVISIBLE);
    }

    @Override
    public void contentLoaded() {
        if (load_avi != null && load_avi.getVisibility() == View.VISIBLE){
            avi.hide();
            load_avi.setVisibility(View.GONE);
        }
    }

    @Override
    public void commentSend() {
        showComment();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wzt);
        weiShuInfoDetailModel = (WeiShuInfoDetailModel)getIntent().getSerializableExtra("model");
        selectIndex = getIntent().getIntExtra("selectIndex",0);
        isDeleteClassify = getIntent().getBooleanExtra("isDeleteClassify", false);
        initView();
        initViewPager();
        initListener();
        getLabel();
        initNav();
        registerBoradcastReceiver();
        updatePublish(false);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (operatingAnim != null && publishing_layout != null && publishing_layout.getVisibility() == View.VISIBLE){
            publishing_icon.clearAnimation();
            publishing_icon.startAnimation(operatingAnim);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isFirstOpen == true){
            isFirstOpen = false;
            boolean isPublish = getIntent().getBooleanExtra("isPublish", false);
            if (isPublish == true){
                Intent intent = new Intent(WZTActivity.this, WZTContentPublishActivity.class);
                intent.putExtra("id",weiShuInfoDetailModel.getId());
                intent.putExtra("contentType",weiShuInfoDetailModel.getContentType());
                startActivityForResult(intent, REQUEST_PUBLISH);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mReceiverTag) {   //判断广播是否注册
            Log.e("TAG","MainActivity广播被注销");
            mReceiverTag = false;   //Tag值 赋值为false 表示该广播已被注销
            unregisterReceiver(mBroadcastReceiver);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if ((requestCode == REQUEST_PUBLISH || requestCode == REQUEST_CONTENT_EDIT) && resultCode == RESULT_OK){
            if (data != null){
                boolean isBacken = data.getBooleanExtra("isBacken", false);
                if (isBacken == true){
                    //发送通知
                    Intent mIntent = new Intent(BroadcastDefine.WZTContentStartPublish_Notify_Action);
                    //发送广播
                    sendBroadcast(mIntent);
                    updatePublish(false);
                    return;
                }
            }
            if (wztContentFragment != null){
                if (viewpager.getCurrentItem() != 0){
                    viewpager.setCurrentItem(0);
                }
                wztContentFragment.getData(true);
            }
        }else if (requestCode == REQUEST_EDIT && resultCode == RESULT_OK){
            getLabel();
        }else if (requestCode == REQUEST_CONTENT_ORDER && resultCode == RESULT_OK){
            if (data != null){
                if (data.getBooleanExtra("isOrdered", false) == true){
                    if (wztContentFragment != null){
                        if (viewpager.getCurrentItem() != 0){
                            viewpager.setCurrentItem(0);
                        }
                        wztContentFragment.getData(true);
                    }
                }
            }
        }
    }

    private void initView() {

        RequestOptions options = new RequestOptions().error(AppThemeUtils.getInstance().getDefaultImageBg()).bitmapTransform(new RoundedCorners(Constant.CornerRadius));//图片圆角


        load_avi = (RelativeLayout) findViewById(R.id.load_avi);
        avi = (AVLoadingIndicatorView) findViewById(R.id.avi);

        wzt_detail_layout = (RelativeLayout) findViewById(R.id.wzt_detail_layout);
        wzt_detail_layout.setClickable(true);
        wzt_detail_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wzt_detail_layout.setVisibility(View.INVISIBLE);
            }
        });
        wzt_detail_layout.setVisibility(View.INVISIBLE);

        wzt_detail_bg = (ImageView) findViewById(R.id.wzt_detail_bg);
        wzt_detail_icon = (ImageView) findViewById(R.id.wzt_detail_icon);
        if (WZTActivity.this != null){
            try {
                Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_detail_bg);
                Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(options).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_detail_icon);
            }catch (Exception e){
                LangPublishActivity.uploadError("加载微纸条背景报错："+e.getLocalizedMessage());
            }
        }

        wzt_detail_icon.setClickable(true);
        wzt_detail_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //View代表方法传入的控件
                float density = ScreenUtils.getScreenDensity(CustomApplication.mContext);
                int[] viewLocation = new int[2];
                view.getLocationInWindow(viewLocation);
                int viewX = viewLocation[0]; // x 坐标
                int viewY = viewLocation[1];
                Intent intent = new Intent(WZTActivity.this, SelfImagePreviewActivity.class);
                intent.putExtra("imgH",(int)(130*density));
                intent.putExtra("imgs",weiShuInfoDetailModel.getCover());
                intent.putExtra("position",0);
                intent.putExtra("isListImg",false);
                intent.putExtra("viewX",viewX);
                intent.putExtra("viewY",viewY);
                intent.putExtra("imgW",(int)(130*density));
                startActivity(intent);
                overridePendingTransition(0,0);//可以通过参数设置关闭与要显示的动画效果,0表示无效果.

            }
        });

        wzt_detail_title = (TextView) findViewById(R.id.wzt_detail_title);
        wzt_detail_title.setText(weiShuInfoDetailModel.getTitle());

        wzt_detail_label_1 = (TextView) findViewById(R.id.wzt_detail_label_1);
        wzt_detail_label_2 = (TextView) findViewById(R.id.wzt_detail_label_2);
        wzt_detail_label_3 = (TextView) findViewById(R.id.wzt_detail_label_3);

        wzt_detail_label_1.setClickable(true);
        wzt_detail_label_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(weiShuInfoDetailModel != null && !CommonUtils.isEmpty(weiShuInfoDetailModel.getLabelName())){
                    List<String> l = CommonUtils.stringToArrayList(weiShuInfoDetailModel.getLabelName());
                    if (l != null && l.size() > 0){
                        Intent intent = new Intent(WZTActivity.this, WZTListActivity.class);
                        intent.putExtra("title",l.get(0));
                        startActivity(intent);
                    }

                }
            }
        });
        wzt_detail_label_2.setClickable(true);
        wzt_detail_label_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(weiShuInfoDetailModel != null && !CommonUtils.isEmpty(weiShuInfoDetailModel.getLabelName())){
                    List<String> l = CommonUtils.stringToArrayList(weiShuInfoDetailModel.getLabelName());
                    if (l != null && l.size() > 1){
                        Intent intent = new Intent(WZTActivity.this, WZTListActivity.class);
                        intent.putExtra("title",l.get(1));
                        startActivity(intent);
                    }
                }

            }
        });
        wzt_detail_label_3.setClickable(true);
        wzt_detail_label_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(weiShuInfoDetailModel != null && !CommonUtils.isEmpty(weiShuInfoDetailModel.getLabelName())){
                    List<String> l = CommonUtils.stringToArrayList(weiShuInfoDetailModel.getLabelName());
                    if (l != null && l.size() > 2){
                        Intent intent = new Intent(WZTActivity.this, WZTListActivity.class);
                        intent.putExtra("title",l.get(2));
                        startActivity(intent);
                    }
                }

            }
        });

        wzt_detail_classify = (LinearLayout) findViewById(R.id.wzt_detail_classify);
        wzt_detail_classify_text = (TextView) findViewById(R.id.wzt_detail_classify_text);

        wzt_detail_location_text = (TextView) findViewById(R.id.wzt_detail_location_text);
        if (CommonUtils.isEmpty(weiShuInfoDetailModel.getLocation())){
            wzt_detail_location_text.setText("位置：无");
        }else {
            wzt_detail_location_text.setText("位置："+weiShuInfoDetailModel.getCity()+" · "+weiShuInfoDetailModel.getLocation());
        }

        wzt_detail_layout_text = (TextView) findViewById(R.id.wzt_detail_layout_text);
        wzt_detail_layout_text.setText(weiShuInfoDetailModel.getDetail());

        appbar = (AppBarLayout) findViewById(R.id.appbar);
        viewpager = (ViewPager) findViewById(R.id.view_pager);
        iv_parallax = (ImageView) findViewById(R.id.iv_parallax);//背景图片
        rl_allinfo = (RelativeLayout) findViewById(R.id.rl_allinfo);

        wzt_icon = (ImageView) findViewById(R.id.wzt_icon);
        if (WZTActivity.this != null){
            try {
                Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(options).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_icon);
            }catch (Exception e){
                LangPublishActivity.uploadError("加载微纸条背景报错："+e.getLocalizedMessage());
            }
        }
        wzt_icon.setClickable(true);
        wzt_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDetail();
            }
        });
        wzt_title = (TextView) findViewById(R.id.wzt_title);
        wzt_title.setText(weiShuInfoDetailModel.getTitle());
        wzt_title.setClickable(true);
        wzt_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDetail();
            }
        });
        wzt_detail = (TextView) findViewById(R.id.wzt_detail);
        wzt_detail.setText(weiShuInfoDetailModel.getDetail());
        wzt_detail_parent = (RelativeLayout) findViewById(R.id.wzt_detail_parent);
        wzt_detail_parent.setClickable(true);
        wzt_detail_parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDetail();
            }
        });

        wzt_user_header = (ImageView) findViewById(R.id.wzt_user_header);
        if (WZTActivity.this != null){
            try {
                Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getHeader()).transform(new CircleTransform(WZTActivity.this)).dontAnimate().into(wzt_user_header);
            }catch (Exception e){
                LangPublishActivity.uploadError("加载微纸条背景报错："+e.getLocalizedMessage());
            }
        }
        wzt_user_private = (ImageView) findViewById(R.id.wzt_user_private);
        if (CommonUtils.isEmpty(weiShuInfoDetailModel.getPrivateIcon())){
            wzt_user_private.setVisibility(View.GONE);
        }else {
            wzt_user_private.setVisibility(View.VISIBLE);
            if (WZTActivity.this != null){
                try {
                    Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getPrivateIcon()).transform(new CircleTransform(WZTActivity.this)).dontAnimate().into(wzt_user_private);
                }catch (Exception e){
                    LangPublishActivity.uploadError("加载微纸条背景报错："+e.getLocalizedMessage());
                }
            }
        }
        wzt_user_nickanme = (TextView) findViewById(R.id.wzt_user_nickanme);
        wzt_user_nickanme.setText(weiShuInfoDetailModel.getNickname());
        wzt_user_layout = (RelativeLayout) findViewById(R.id.wzt_user_layout);
        wzt_user_layout.setClickable(true);
        wzt_user_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //进入个人主页
                Intent intent = new Intent(WZTActivity.this, UserLangActivity.class);
                intent.putExtra(APIKey.useridKey,weiShuInfoDetailModel.getUserid());
                intent.putExtra(APIKey.typeKey,1);
                intent.putExtra(APIKey.titleKey,weiShuInfoDetailModel.getNickname());
                startActivity(intent);
            }
        });

        wzt_subscribe_layout = (RelativeLayout) findViewById(R.id.wzt_subscribe_layout);
        wzt_subscribe_layout.setClickable(true);
        wzt_subscribe_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                subscribe();
            }
        });
        wzt_subscribe_icon = (ImageView) findViewById(R.id.wzt_subscribe_icon);
        wzt_subscribe_text = (TextView) findViewById(R.id.wzt_subscribe_text);
        if (weiShuInfoDetailModel.isSubscribe() == true){
            wzt_subscribe_icon.setImageResource(R.drawable.wzt_collection_sel);
            wzt_subscribe_text.setText("取消订阅");
        }else {
            wzt_subscribe_icon.setImageResource(R.drawable.wzt_collection);
            wzt_subscribe_text.setText("订阅");
        }
        wzt_subscribe_count = (TextView) findViewById(R.id.wzt_subscribe_count);
        wzt_subscribe_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getCollectCount()));

        wzt_like_layout = (RelativeLayout) findViewById(R.id.wzt_like_layout);
        wzt_like_layout.setClickable(true);
        wzt_like_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                like();
            }
        });
        wzt_like_icon = (ImageView) findViewById(R.id.wzt_like_icon);
        wzt_like_text = (TextView) findViewById(R.id.wzt_like_text);
        if (weiShuInfoDetailModel.isLike() == true){
            wzt_like_icon.setImageResource(R.drawable.wzt_like_sel);
        }else {
            wzt_like_icon.setImageResource(R.drawable.wzt_like);
        }
        wzt_like_count = (TextView) findViewById(R.id.wzt_like_count);
        wzt_like_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getLikeCount()));

        wzt_comment_layout = (RelativeLayout) findViewById(R.id.wzt_comment_layout);
        wzt_comment_layout.setClickable(true);
        wzt_comment_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showComment();
            }
        });
        wzt_comment_icon = (ImageView) findViewById(R.id.wzt_comment_icon);
        wzt_comment_text = (TextView) findViewById(R.id.wzt_comment_text);
        wzt_comment_count = (TextView) findViewById(R.id.wzt_comment_count);
        wzt_comment_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getCommentCount()));

        wzt_share_layout = (RelativeLayout) findViewById(R.id.wzt_share_layout);
        wzt_share_layout.setClickable(true);
        wzt_share_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare();
            }
        });
        wzt_share_icon = (ImageView) findViewById(R.id.wzt_share_icon);
        wzt_share_text = (TextView) findViewById(R.id.wzt_share_text);
        wzt_share_count = (TextView) findViewById(R.id.wzt_share_count);

        wzt_location_layout = (RelativeLayout) findViewById(R.id.wzt_location_layout);
        wzt_location_layout.setClickable(true);
        wzt_location_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               onClickLocation();
            }
        });
        wzt_location_icon = (ImageView) findViewById(R.id.wzt_location_icon);
        wzt_location_text = (TextView) findViewById(R.id.wzt_location_text);
        wzt_location_count = (TextView) findViewById(R.id.wzt_location_count);
        if (CommonUtils.isEmpty(weiShuInfoDetailModel.getLocation())){
            wzt_location_count.setText("无");
        }else {
            wzt_location_count.setText(weiShuInfoDetailModel.getLocation());
        }
        wzt_detail_location = (LinearLayout) findViewById(R.id.wzt_detail_location);
        wzt_detail_location.setClickable(true);
        wzt_detail_location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickLocation();
            }
        });

        int width = ScreenUtils.getScreenWidth(WZTActivity.this);
        float density = ScreenUtils.getScreenDensity(WZTActivity.this);
        topHeight = (int)((64+25+130+25+40+25)*density);
        ViewGroup.LayoutParams params = appbar.getLayoutParams();
        params.width = width;
        params.height = topHeight;
        appbar.setLayoutParams(params);

        params = iv_parallax.getLayoutParams();
        params.width = width;
        params.height = width;
        iv_parallax.setLayoutParams(params);

        if (WZTActivity.this != null){
            try {
                Glide.with(this).load(R.mipmap.bg_home).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(iv_parallax);
                Glide.with(this).load(weiShuInfoDetailModel.getCover()).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(iv_parallax);
            }catch (Exception e){
                LangPublishActivity.uploadError("加载微纸条背景报错："+e.getLocalizedMessage());
            }
        }
        //refreshLayout = (SmartRefreshLayout) findViewById(R.id.refreshLayout);

        title_layout = (RelativeLayout) findViewById(R.id.title_layout);
        collapsing_toolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        View tabs_line = (View) findViewById(R.id.tabs_line);
        tabs_line.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());
        View tabs_line_up = (View) findViewById(R.id.tabs_line_up);
        tabs_line_up.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_back.setBackgroundResource(R.mipmap.back_white);
        iv_back_layout = (RelativeLayout) findViewById(R.id.iv_back_layout);
        iv_back_layout.setClickable(true);
        iv_back_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updatePublish(true);
                finish();
            }
        });
        iv_date = (ImageView) findViewById(R.id.iv_date);
        if (CommonUtils.isLogin() == false || weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == false){
            iv_date.setBackgroundResource(R.drawable.more);
        }else {
            iv_date.setBackgroundResource(R.drawable.whiteadd);
        }
        iv_date_layout = (RelativeLayout) findViewById(R.id.iv_date_layout);
        iv_date_layout.setClickable(true);
        iv_date_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                moreMenu();
            }
        });
        //初始化沉浸式
        mImmersionBar.titleBar(toolbar).init();

        publishing_layout = (LinearLayout) findViewById(R.id.publishing_layout);
        publishing_icon = (ImageView) findViewById(R.id.publishing_icon);
        publishing_text = (TextView) findViewById(R.id.publishing_text);
        operatingAnim = AnimationUtils.loadAnimation(WZTActivity.this, R.anim.tip);
        LinearInterpolator lin = new LinearInterpolator();
        operatingAnim.setInterpolator(lin);
    }

    /**
     * 设置item
     * @param
     */
    private void initViewPager() {
        boolean canPublish = false;
        if (CommonUtils.isLogin() == false || weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == false){
            if (weiShuInfoDetailModel.getType() == 2){
                canPublish = true;
            }
        }else {
            canPublish = true;
        }
        viewpager = (ViewPager) findViewById(R.id.view_pager);
        AdapterPage adapter = new AdapterPage(getSupportFragmentManager());
        wztContentFragment = WZTContentFragment.newInstance(weiShuInfoDetailModel.getId(), weiShuInfoDetailModel.getUserid(), weiShuInfoDetailModel.getContentType(), weiShuInfoDetailModel.isCanBrowseAll(), weiShuInfoDetailModel.isNeedCare(), weiShuInfoDetailModel.isCareState(), canPublish, weiShuInfoDetailModel.getTitle());
        adapter.addFragment( wztContentFragment, "内容");
        wztCommentFragment = WZTCommentFragment.newInstance(weiShuInfoDetailModel.getId(), weiShuInfoDetailModel.getUserid());
        adapter.addFragment(wztCommentFragment, "评论");
        adapter.addFragment(WZTLikeFragment.newInstance(weiShuInfoDetailModel.getId()), "喜欢");
        adapter.addFragment(WZTSubscribeFragment.newInstance(weiShuInfoDetailModel.getId()), "订阅");
        viewpager.setAdapter(adapter);
        //解决卡顿问题：https://blog.csdn.net/weixin_34023982/article/details/87958336
        viewpager.setOffscreenPageLimit(adapter.getCount());//将viewpager的缓存个数设置为fragment的个数

        //设置tablayout，viewpager上的标题
        tabLayout.setupWithViewPager(viewpager);
        tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.lightGreenColor));
        tabLayout.setTabTextColors(Color.parseColor("#757D88"),Color.parseColor("#99CC00"));
        tabLayout.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
        viewpager.setCurrentItem(selectIndex);
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        /*
        //这里有问题：第三方库https://blog.csdn.net/tongzhengtong/article/details/88656580
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout,30,30);
            }
        });
        */
    }

    private void initListener() {
        /*
        refreshLayout.setEnableRefresh(false);
        refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
            @Override
            public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
                super.onHeaderMoving(header, isDragging, percent, offset, headerHeight, maxDragHeight);
                mOffset = offset / 2;
                iv_parallax.setTranslationY(mOffset);
            }

        });
        */

        appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                iv_parallax.setTranslationY(verticalOffset);
                //200是appbar的高度
                if (Math.abs(verticalOffset) == topHeight - toolbar.getHeight()) {//关闭DensityUtil.dp2px(200)
                    /*
                    if (iswhite) {//变黑
                        if (ImmersionBar.isSupportStatusBarDarkFont()) {
                            mImmersionBar.statusBarDarkFont(true).init();
                            isblack = true;
                            iswhite = false;
                        }
                    }
                    //buttonBarLayout.setVisibility(View.VISIBLE);
                    //title_layout.setVisibility(View.VISIBLE);

                    collapsing_toolbar.setContentScrimResource(R.color.white);
                    iv_back.setBackgroundResource(R.mipmap.back_black);
                    iv_date.setBackgroundResource(R.mipmap.date_black);
//                  */
                    rl_allinfo.setVisibility(View.INVISIBLE);
                } else {  //展开
                    if (isblack) { //变白
                        mImmersionBar.statusBarDarkFont(false).init();
                        isblack = false;
                        iswhite = true;
                    }
                    //buttonBarLayout.setVisibility(View.INVISIBLE);
                    //title_layout.setVisibility(View.VISIBLE);
                    rl_allinfo.setVisibility(View.VISIBLE);
                    collapsing_toolbar.setContentScrimResource(R.color.transparent);
                    if (CommonUtils.isLogin() == false || weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == false){
                        iv_date.setBackgroundResource(R.drawable.more);
                    }else {
                        iv_date.setBackgroundResource(R.drawable.whiteadd);
                    }

//                    toolbar.setVisibility(View.INVISIBLE);
                }
            }
        });
    }

    /**
     * 通过反射修改踏遍layout的宽，其实相当于margin
     * @param tabs
     * @param leftDip
     * @param rightDip
     */
    public void setIndicator (TabLayout tabs, int leftDip, int rightDip) {
        Class<?> tabLayout = tabs.getClass();
        Field tabStrip = null;
        try {
            tabStrip = tabLayout.getDeclaredField("mTabStrip");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        tabStrip.setAccessible(true);
        LinearLayout llTab = null;
        try {
            llTab = (LinearLayout) tabStrip.get(tabs);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, leftDip, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rightDip, Resources.getSystem().getDisplayMetrics());

        for (int i = 0; i < llTab.getChildCount(); i++) {
            View child = llTab.getChildAt(i);
            child.setPadding(0, 0, 0, 0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            child.setLayoutParams(params);
            child.invalidate();
        }
    }


    //更多菜单
    private void moreMenu(){
        final List<String> menu = new ArrayList<>();
        if (CommonUtils.isLogin() == false || weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == false){
            if (weiShuInfoDetailModel.getType() == 2){
                menu.add("发布内容");
            }
            menu.add("发表评论");
            if (weiShuInfoDetailModel.isSubscribe() == false){
                menu.add("订阅");
            }
            menu.add("举报");
        }else {
            if (weiShuInfoDetailModel.getContentType() == 2){
                menu.add("写日记");
            }else {
                menu.add("发布内容");
            }
            menu.add("编辑微纸条");
            menu.add("发表评论");
            menu.add("内容排序");
            if (!CommonUtils.isEmpty(weiShuInfoDetailModel.getClassifyName()) && weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == true){
                menu.add("从当前分类移除");
            }
            menu.add("删除微纸条");
        }
        menu.add("进入阅读模式");
        ActionSheetDialog actionSheetDialog = new ActionSheetDialog(WZTActivity.this)
                .builder()
                .setTitle("请选择")
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        for (String s : menu){
            actionSheetDialog.addSheetItem(s, null, new ActionSheetDialog.OnSheetItemClickListener() {
                @Override
                public void onClick(int which) {
                    if (which > 0){
                        which -= 1;
                        String title = menu.get(which);
                        if (title.equals("发布内容") || title.equals("写日记")){

                            if (bindMobile() == true){
                                return;
                            }

                           Intent intent = new Intent(WZTActivity.this, WZTContentPublishActivity.class);
                           intent.putExtra("id",weiShuInfoDetailModel.getId());
                           intent.putExtra("contentType",weiShuInfoDetailModel.getContentType());
                           startActivityForResult(intent, REQUEST_PUBLISH);
                        }else if (title.equals("发表评论")){
                            showComment();
                        }else if (title.equals("订阅")){
                            subscribe();
                        }else if (title.equals("举报")){
                            report(weiShuInfoDetailModel.getId()+"", 4);
                        }else if (title.equals("编辑微纸条")){
                            Intent intent = new Intent(WZTActivity.this, WZTPublishActivity.class);
                            Bundle bundle=new Bundle();
                            bundle.putSerializable("model", weiShuInfoDetailModel);//序列化
                            intent.putExtras(bundle);//发送数据
                            startActivityForResult(intent, REQUEST_EDIT);
                        }else if (title.equals("从当前分类移除")){
                            deleteFromCurrentClassify();
                        }else if (title.equals("内容排序")){
                            Intent intent = new Intent(WZTActivity.this, WZTContentOrderActivity.class);
                            intent.putExtra("contentType", weiShuInfoDetailModel.getContentType());
                            intent.putExtra("canBrowseAll", true);
                            intent.putExtra("wztUserId", weiShuInfoDetailModel.getUserid());
                            intent.putExtra("id", weiShuInfoDetailModel.getId());
                            startActivityForResult(intent, REQUEST_CONTENT_ORDER);
                        }else if (title.equals("进入阅读模式")){
                            Intent intent = new Intent(WZTActivity.this, WZTCardActivity.class);
                            Bundle bundle=new Bundle();
                            bundle.putSerializable("model", weiShuInfoDetailModel);//序列化
                            intent.putExtras(bundle);//发送数据
                            intent.putExtra("selectIndex",selectIndex);
                            startActivity(intent);
                        }else if (title.equals("删除微纸条")){
                            CustomDialog dialog = null;
                            final CustomDialog.Builder builder = new CustomDialog.Builder(WZTActivity.this);
                            builder.setTitle("温馨提示");
                            builder.setMessage("微纸条删除后将无法恢复，确定要删除吗？");
                            builder.setPositiveButton("删除", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    final HashMap<String, String> map = new HashMap<String, String>();
                                    map.put(APIKey.tokenKey, CommonUtils.formatString(CustomApplication.loginModel.getToken()));
                                    map.put("token", CustomApplication.loginModel.getToken());
                                    map.put("id", weiShuInfoDetailModel.getId()+"");
                                    String url = "weishu/theme/delete.do";
                                    HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                                        @Override
                                        public void onSuccess(String data) {
                                            CommonModel commonModel = GsonTools.getCommonModel(data);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    if(commonModel.getFlag().equals("1")){
                                                        ToastUtil.show(WZTActivity.this, "删除成功");
                                                        Intent mIntent = new Intent(BroadcastDefine.WZT_Delete_Notify_Action);
                                                        //发送广播
                                                        sendBroadcast(mIntent);
                                                        finish();
                                                    }else {
                                                        ToastUtil.show(WZTActivity.this, commonModel.getMsg());
                                                    }
                                                }
                                            });
                                        }

                                        @Override
                                        public void onError(String msg) {
                                             runOnUiThread(new Runnable() {
                                                 @Override
                                                 public void run() {
                                                     ToastUtil.show(WZTActivity.this, "删除失败");
                                                 }
                                             });
                                        }
                                    });
                                }
                            });
                            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            dialog = builder.create();
                            dialog.show();
                        }
                    }
                }
            });
        }
        actionSheetDialog.show();
    }

    //从当前分类移除
    private void deleteFromCurrentClassify(){
        avi.show();
        final HashMap<String, String> map = new HashMap<String, String>();
        String url = "weishu/classify/wzt/delete.do";
        map.put(APIKey.tokenKey, CommonUtils.formatString(CustomApplication.loginModel.getToken()));
        map.put("classifyId", ""+weiShuInfoDetailModel.getClassifyId());
        map.put("weishuId", ""+weiShuInfoDetailModel.getId());
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                CommonModel commonModel = GsonTools.getCommonModel(data);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        avi.hide();
                        if (commonModel.getFlag().equals("1")){
                            ToastUtil.show(WZTActivity.this, "移除成功");
                            weiShuInfoDetailModel.setClassifyIcon("");
                            weiShuInfoDetailModel.setClassifyName("");
                            weiShuInfoDetailModel.setClassifyId(0);
                            if (CommonUtils.isEmpty(weiShuInfoDetailModel.getClassifyName())){
                                wzt_detail_classify_text.setText("分类：无");
                            }else {
                                wzt_detail_classify_text.setText("分类："+weiShuInfoDetailModel.getClassifyName());
                            }
                            if (isDeleteClassify == true){
                                setResult(RESULT_OK);
                                finish();
                            }
                        }else {
                            CustomApplication.showTip(commonModel, WZTActivity.this);
                        }
                    }
                });
            }

            @Override
            public void onError(String msg) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        avi.hide();
                        ToastUtil.show(WZTActivity.this, "添加失败，请稍后尝试~");
                    }
                });
            }
        });
    }

    //举报
    private void report(String reportId, int reportType){//reportType:1-举报人；2-举报微句；3-举报评论；4-举报微纸条；5-举报微纸条内容；6-举报微纸条评论
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(WZTActivity.this, LoginActivity.class);
            startActivity(intent);
            return;
        }
        Intent intent = new Intent(WZTActivity.this, ReportActivity.class);
        intent.putExtra(APIKey.idKey,reportId);
        intent.putExtra(APIKey.typeKey,reportType);
        startActivity(intent);
    }

    //评论
    private void showComment(){

        if (viewpager.getCurrentItem() != 1){
            viewpager.setCurrentItem(1);
        }

        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(WZTActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }

        if (CommonUtils.bindMobile(WZTActivity.this) == true){
            return;
        }

        dialog = new KeyMapDailog("发表评论...", new KeyMapDailog.SendBackListener() {
            @Override
            public void sendBack(final String inputText) {
                if (inputText == null || inputText.length() == 0){
                    return;
                }
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //dialog.hideProgressdialog();
                        dialog.dismiss();
                        //hintKeyBoard();

                        new Thread(){
                            @Override
                            public void run() {
                                super.run();
                                final HashMap<String, String> map = new HashMap<String, String>();
                                map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                                map.put("dataId", weiShuInfoDetailModel.getId()+"");
                                map.put("dataUserId","");
                                map.put("dataType","0");
                                map.put("dataContent",inputText);
                                map.put("dataAnswerId","0");
                                String url = "weishu/theme/comment.do";
                                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                                    @Override
                                    public void onSuccess(String data) {
                                        Log.e("TAG","评论结果："+data);
                                        final CommonModel commonModel = GsonTools.getCommonModel(data);
                                        if (commonModel.getFlag().equals("1")){
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    dialog.dismiss();
                                                    ToastUtil.show(WZTActivity.this, "评论成功");
                                                    DryCommentModel dryCommentModel = new DryCommentModel();
                                                    dryCommentModel.setContent(inputText);
                                                    dryCommentModel.setUserid(CustomApplication.loginModel.getUid());
                                                    dryCommentModel.setHeader(CustomApplication.loginModel.getHeader());
                                                    dryCommentModel.setNickname(CustomApplication.loginModel.getNickname());
                                                    dryCommentModel.setTime(System.currentTimeMillis()+"");
                                                    dryCommentModel.setCcount("0");
                                                    dryCommentModel.setLcount("0");
                                                    dryCommentModel.setIslike("0");
                                                    dryCommentModel.setSharecount("0");
                                                    dryCommentModel.setCollectcount("0");
                                                    dryCommentModel.setIscollect("0");
                                                    dryCommentModel.setType("0");
                                                    dryCommentModel.setSourceid(weiShuInfoDetailModel.getId()+"");
                                                    dryCommentModel.setCommentid(commonModel.getData()+"");
                                                    double v = Double.valueOf(dryCommentModel.getCommentid());
                                                    int n = (int)v;
                                                    dryCommentModel.setCommentid(n+"");
                                                    Log.e("TAG","评论id"+commonModel.getData());
                                                    weiShuInfoDetailModel.setCommentCount(weiShuInfoDetailModel.getCommentCount()+1);
                                                    wzt_comment_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getCommentCount()));
                                                    if (wztCommentFragment != null){
                                                        wztCommentFragment.addComment(dryCommentModel);
                                                    }
                                                }
                                            });
                                        }else {
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    ToastUtil.show(WZTActivity.this, commonModel.getMsg());
                                                }
                                            });
                                        }
                                    }

                                    @Override
                                    public void onError(String msg) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                ToastUtil.show(WZTActivity.this, "提交失败");
                                            }
                                        });
                                    }
                                });
                            }
                        }.start();
                    }
                }, 5);
            }
        });
        dialog.show(getSupportFragmentManager(), "dialog");
    }

    //分享
    private void showShare(){

        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(WZTActivity.this, LoginActivity.class);
            startActivity(intent);
            return;
        }

        if (weiShuInfoDetailModel.getVisible() == false){
            ToastUtil.show(WZTActivity.this, "私密微纸条不能分享");
            return;
        }
        if (weiShuInfoDetailModel.getStatus() == 0 || weiShuInfoDetailModel.getStatus() == 2){
            ToastUtil.show(WZTActivity.this, "发布内容过少，暂不允许分享。");
            return;
        }

        if (weiShuInfoDetailModel.isNeedAuth() == true){
            if (weiShuInfoDetailModel.getUserid().equals(CustomApplication.loginModel.getUid()) == false){
                ToastUtil.show(WZTActivity.this, "授权分类下的微纸条，只有作者才可以分享");
                return;
            }
        }

        Intent intent = new Intent(WZTActivity.this, WZTShareActivity.class);
        Bundle bundle=new Bundle();
        bundle.putSerializable("model", weiShuInfoDetailModel);//序列化
        intent.putExtras(bundle);//发送数据
        startActivity(intent);
    }

    //订阅
    private void subscribe(){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(WZTActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("dataId", weiShuInfoDetailModel.getId()+"");
        String url = "weishu/theme/care.do";
        if (weiShuInfoDetailModel.isSubscribe() == true){
            url = "weishu/theme/care/cancel.do";
            weiShuInfoDetailModel.setSubscribe(false);
            if (weiShuInfoDetailModel.getCollectCount() > 0){
                weiShuInfoDetailModel.setCollectCount(weiShuInfoDetailModel.getCollectCount()-1);
            }
        }else {
            weiShuInfoDetailModel.setSubscribe(true);
            weiShuInfoDetailModel.setCollectCount(weiShuInfoDetailModel.getCollectCount()+1);
        }
        if (weiShuInfoDetailModel.isSubscribe() == true){
            wzt_subscribe_icon.setImageResource(R.drawable.wzt_collection_sel);
            wzt_subscribe_text.setText("取消订阅");
        }else {
            wzt_subscribe_icon.setImageResource(R.drawable.wzt_collection);
            wzt_subscribe_text.setText("订阅");
        }
        wzt_subscribe_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getCollectCount()));

        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){

                }else {
                    //CustomApplication.showTip(commonModel, WZTActivity.this);
                }
            }

            @Override
            public void onError(String msg) {

            }
        });
    }

    //喜欢
    private void like(){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(WZTActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        if (weiShuInfoDetailModel.isLike() == true){
            weiShuInfoDetailModel.setLike(false);
            weiShuInfoDetailModel.setLikeCount(weiShuInfoDetailModel.getLikeCount()-1);
            wzt_like_icon.setImageResource(R.drawable.wzt_like);
        }else {
            weiShuInfoDetailModel.setLike(true);
            weiShuInfoDetailModel.setLikeCount(weiShuInfoDetailModel.getLikeCount()+1);
            wzt_like_icon.setImageResource(R.drawable.wzt_like_sel);
        }
        wzt_like_count.setText(CommonUtils.getDisplayCount(weiShuInfoDetailModel.getLikeCount()));

        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("id", weiShuInfoDetailModel.getId()+"");
        String url = "weishu/theme/like.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                }else {
                    CustomApplication.showTip(commonModel, WZTActivity.this);
                }
            }

            @Override
            public void onError(String msg) {

            }
        });
    }

    //展示详情
    private void showDetail(){
        wzt_detail_layout.setVisibility(View.VISIBLE);
    }

    //获取标签
    private void getLabel(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                final HashMap<String, String> map = new HashMap<String, String>();
                map.put(APIKey.idKey, weiShuInfoDetailModel.getId()+"");
                map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
                String url = "weishu/theme/info.do";
                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                    @Override
                    public void onSuccess(String data) {
                        CommonModel commonModel = GsonTools.getCommonModel(data);
                        if (commonModel.getFlag().equals("1")){
                            WeiShuInfoDetailModel langInfoModel = GsonTools.getWeiShuInfo(data);
                            if (langInfoModel != null){
                                weiShuInfoDetailModel = langInfoModel;
                            }
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (CommonUtils.isEmpty(weiShuInfoDetailModel.getLabelName())){
                                        wzt_detail_label_1.setVisibility(View.GONE);
                                        wzt_detail_label_2.setVisibility(View.GONE);
                                        wzt_detail_label_3.setVisibility(View.GONE);
                                    }else {
                                        List<String> l = CommonUtils.stringToArrayList(weiShuInfoDetailModel.getLabelName());
                                        if (l.size() == 1){
                                            wzt_detail_label_1.setVisibility(View.VISIBLE);
                                            wzt_detail_label_1.setText(l.get(0));
                                            wzt_detail_label_2.setVisibility(View.GONE);
                                            wzt_detail_label_3.setVisibility(View.GONE);
                                        }else if (l.size() == 2){
                                            wzt_detail_label_1.setVisibility(View.VISIBLE);
                                            wzt_detail_label_1.setText(l.get(0));
                                            wzt_detail_label_2.setVisibility(View.VISIBLE);
                                            wzt_detail_label_2.setText(l.get(1));
                                            wzt_detail_label_3.setVisibility(View.GONE);
                                        }else {
                                            wzt_detail_label_1.setVisibility(View.VISIBLE);
                                            wzt_detail_label_1.setText(l.get(0));
                                            wzt_detail_label_2.setVisibility(View.VISIBLE);
                                            wzt_detail_label_2.setText(l.get(1));
                                            wzt_detail_label_3.setVisibility(View.VISIBLE);
                                            wzt_detail_label_3.setText(l.get(2));
                                        }
                                    }

                                    wzt_detail_title.setText(weiShuInfoDetailModel.getTitle());

                                    if (CommonUtils.isEmpty(weiShuInfoDetailModel.getClassifyName())){
                                        wzt_detail_classify_text.setText("分类：无");
                                    }else {
                                        wzt_detail_classify_text.setText("分类："+weiShuInfoDetailModel.getClassifyName());
                                    }

                                    if (CommonUtils.isEmpty(weiShuInfoDetailModel.getLocation())){
                                        wzt_detail_location_text.setText("位置：无");
                                    }else {
                                        wzt_detail_location_text.setText("位置："+weiShuInfoDetailModel.getCity()+" · "+weiShuInfoDetailModel.getLocation());
                                    }
                                    wzt_title.setText(weiShuInfoDetailModel.getTitle());
                                    wzt_detail.setText(weiShuInfoDetailModel.getDetail());
                                    if (WZTActivity.this != null){
                                        try {
                                            RequestOptions options = new RequestOptions().error(AppThemeUtils.getInstance().getDefaultImageBg()).bitmapTransform(new RoundedCorners(Constant.CornerRadius));//图片圆角
                                            Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_detail_bg);
                                            Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(options).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_detail_icon);
                                            Glide.with(WZTActivity.this).load(weiShuInfoDetailModel.getCover()).apply(options).placeholder(R.mipmap.bg_home).dontAnimate().into(wzt_icon);
                                        }catch (Exception e){
                                            LangPublishActivity.uploadError("第二次加载微纸条背景图报错："+e.getLocalizedMessage());
                                        }
                                    }


                                }
                            });
                        }else {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    CustomApplication.showTip(commonModel, WZTActivity.this);
                                }
                            });
                        }
                    }

                    @Override
                    public void onError(String msg) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                            }
                        });
                    }
                });
            }
        }).start();
    }

    //位置信息
    private void onClickLocation()
    {
        if (CommonUtils.isEmpty(weiShuInfoDetailModel.getLocation())){
            return;
        }

        if (mapList == null || mapList.size() == 0){
            return;
        }
        ActionSheetDialog actionSheetDialog = new ActionSheetDialog(WZTActivity.this)
                .builder()
                .setTitle("请选择")
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        for (String s : mapList){
            actionSheetDialog.addSheetItem(s, null, new ActionSheetDialog.OnSheetItemClickListener() {
                @Override
                public void onClick(int which) {
                    if (which > 0){
                        String title = mapList.get(which-1);
                        if (title.equals("高德地图")){
                            gaodeNav(weiShuInfoDetailModel.getCity(),weiShuInfoDetailModel.getLocation(),weiShuInfoDetailModel.getLatitude()+"",weiShuInfoDetailModel.getLongtitude()+"");
                        }else if (title.equals("百度地图")){
                            baiduNav(weiShuInfoDetailModel.getCity(),weiShuInfoDetailModel.getLocation(),weiShuInfoDetailModel.getLatitude()+"",weiShuInfoDetailModel.getLongtitude()+"");
                        }else if (title.equals("腾讯地图")){
                            openTencentMap(WZTActivity.this, 0, 0, null, weiShuInfoDetailModel.getLatitude(), weiShuInfoDetailModel.getLongtitude(), weiShuInfoDetailModel.getLocation());
                        }
                    }
                }
            });
        }
        actionSheetDialog.show();
    }

    //以下是导航相关
    private void initNav(){
        if (mapList == null){
            mapList = new ArrayList<String>();
        }
        if (mapList.size() == 0){
            if (isInstallByread(PACKEGE_GAODE)){
                mapList.add("高德地图");
            }
            if(isInstallByread(PACKEGE_BAIDU)){
                mapList.add("百度地图");
            }
            if (isInstallByread(PN_TENCENT_MAP)){
                mapList.add("腾讯地图");
            }
        }
    }


    /**
     * 判断是否安装目标应用
     * @param packageName 目标应用安装后的包名
     * @return 是否已安装目标应用
     */
    private boolean isInstallByread(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }

    /**
     * 城市名 位置名  目的地纬度 目的地经度
     */
    private void baiduNav(String city, String position,String lat,String lon) {
        Intent intent = new Intent();
        // 驾车路线规划
        intent.setData(Uri.parse("baidumap://map/direction?"+"origin="+CustomApplication.latitude+","+CustomApplication.longtitude+"&region="+city+"&destination="+position+"&mode=driving"));//walking
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        //对局部细节进行了优化。
    }

    //高德导航
    private void gaodeNav(String city, String position,String lat,String lon){
        try {
            Intent intent=Intent.parseUri("androidamap://viewMap?sourceApplication=appname&poiname="+position+"&lat="+lat+"&lon="+lon+"&dev=0",0);;
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }


    /**
     * 打开腾讯地图
     * params 参考http://lbs.qq.com/uri_v1/guide-route.html
     *
     * @param context
     * @param slat 起点纬度
     * @param slon 起点经度
     * @param sname 起点名称 可不填（0,0，null）
     * @param dlat 终点纬度
     * @param dlon 终点经度
     * @param dname 终点名称 必填
     * 驾车：type=drive，policy有以下取值
    0：较快捷
    1：无高速
    2：距离
    policy的取值缺省为0
     * &from=" + dqAddress + "&fromcoord=" + dqLatitude + "," + dqLongitude + "
     */
    public static void openTencentMap(Context context, double slat, double slon, String sname, double dlat, double dlon, String dname) {
        String uriString = null;
        StringBuilder builder = new StringBuilder("qqmap://map/routeplan?type=drive&policy=0&referer=zhongshuo");
        if (slat != 0) {
            builder.append("&from=").append(sname)
                    .append("&fromcoord=").append(slat)
                    .append(",")
                    .append(slon);
        }
        builder.append("&to=").append(dname)
                .append("&tocoord=").append(dlat)
                .append(",")
                .append(dlon);
        uriString = builder.toString();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setPackage(PN_TENCENT_MAP);
        intent.setData(Uri.parse(uriString));
        context.startActivity(intent);
    }

}
